package com.pb.news.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * ConfigManager--BDQN_WEB_NEWS
 *
 * @author: Jovi
 * @createTime: 2018-03-22 14:14
 **/
public class ConfigManager {

    private static ConfigManager configManager;

    private static Properties properties;

    private ConfigManager() throws IOException {

        String configFile = "database.properties";
        properties = new Properties();
        /* http://blog.csdn.net/bluishglc/article/details/38753047
         * 对Class.getResourceAsStream和
         * ClassLoader.getResourceAsStream方法所使用的资源路径的解释
         */
        InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream(configFile);

        properties.load(is);
        is.close();
    }

    public static ConfigManager getInstance() throws IOException {

        if (configManager == null) {
            configManager = new ConfigManager();
        }
        return configManager;
    }

    public String getString(String key) {
        return properties.getProperty(key);
    }


}
